package demo.vo;

import demo.java.time.DateTimeDemo;
import lombok.Getter;
import lombok.Setter;
import org.springframework.data.mongodb.core.mapping.Document;

import java.time.*;
import java.util.Date;

@Document(collection = "test")
@Setter
@Getter
public class TimeDemoVO {

    private int id;

    private Date date;

    private Instant instant;

    private LocalDateTime localDateTime;

    private LocalDate localDate;

    private LocalTime localTime;

    private OffsetDateTime offsetDateTime;

    private ZonedDateTime zonedDateTime;

    public TimeDemoVO() {
    }

    public TimeDemoVO(long ts) {
        this.date = new Date(ts);
        this.instant = Instant.ofEpochMilli(ts);
        this.localDateTime = instant.atZone(ZoneId.systemDefault()).toLocalDateTime();
        this.localDate = localDateTime.toLocalDate();
        this.localTime = localDateTime.toLocalTime();
        this.zonedDateTime = localDateTime.atZone(ZoneId.systemDefault());
        this.offsetDateTime = zonedDateTime.toOffsetDateTime();
    }

    public static TimeDemoVO now() {
        TimeDemoVO vo = new TimeDemoVO();
        vo.setInstant(Instant.now());
        vo.setDate(new Date());
        vo.setLocalDateTime(LocalDateTime.now());
        vo.setLocalDate(vo.getLocalDateTime().toLocalDate());
        vo.setLocalTime(vo.getLocalDateTime().toLocalTime());
        vo.setOffsetDateTime(OffsetDateTime.now());
        vo.setZonedDateTime(ZonedDateTime.now());
        return vo;
    }

    @Override
    public String toString() {
        return "TimeDemoVO{" +
                "id=" + id +
                ", localDateTime=" + localDateTime +
                ", localDate=" + localDate +
                ", localTime=" + localTime +
                ", offsetDateTime=" + offsetDateTime +
                ", zonedDateTime=" + zonedDateTime +
                ", date=" + date +
                '}';
    }

}
